#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int b[N];
vector<int> bian[N];
const int MOD = 998244353;
int qpow(int x,int p){
    int res = 1;
    while(p){
        if(p & 1){
            res = 1ll*x*res%MOD;
        }
        x = 1ll*x*x%MOD;
        p>>=1;
    }
    return res;
}
const int G = 3,GINV = qpow(G,MOD - 2);
const int MB = 19;
vector<int> trs[MB + 1];
vector<int> bg[MB + 1];
vector<int> bginv[MB + 1];
void init(){
    trs[0] = vector<int>(1,0);
    for(int i = 1;i <= MB;i++){
        trs[i] = vector<int>(1<<i);
        bg[i] = vector<int>(1<<i - 1);
        bginv[i] = vector<int>(1<<i - 1);
        for(int j = 0;j < i;j++){
            for(int k = 1<<j;k < (1<<j + 1);k++){
                trs[i][k] = trs[i][k - (1<<j)] | (1<<(i - j - 1));
            }
        }
        bg[i][0] = 1;
        bginv[i][0] = 1;
        int o1 = qpow(G,(MOD - 1)/(1<<i));
        int o2 = qpow(GINV,(MOD - 1)/(1<<i));
        for(int j = 1;j < (1<<i - 1);j++){
            bg[i][j] = 1ll*bg[i][j - 1]*o1%MOD;
            bginv[i][j] = 1ll*bginv[i][j - 1]*o2%MOD;
        }
    }
}

vector<int> FFT(const vector<int> &val,int tot,int lgt,vector<int> *base = bg){
    vector<int> res(tot);
    for(int j = 0;j < tot;j++){
        if(trs[lgt][j] < val.size()){
            res[j] = val[trs[lgt][j]];
        }
    }
    for(int i = 1;i<=lgt;i++){
        int len = 1<<i;
        int hlen = len/2;
        for(int j = 0;j < tot;j += len)
        {
            for(int k = j;k < j + hlen;k++){
                int va = res[k],vb = 1ll*base[i][k - j]*res[k + hlen]%MOD;
                res[k] = (va + vb)%MOD;
                res[k + hlen] = (va - vb + MOD)%MOD;
            }
        }
    }
    return res;
}

vector<int> IFFT(const vector<int> &val,int tot,int lgt){
    return FFT(val,tot,lgt,bginv);
}

vector<int> operator*(const vector<int> &va,const vector<int> &vb){
    if(va.size() == 1 && va[0] == 0){
        return {0};
    }
    if(vb.size() == 1 && vb[0] == 0){
        return {0};
    }
    int n = va.size() - 1;
    int m = vb.size() - 1;
    int tot = 1;
    int lgt = 0;
    while(tot <= n + m){
        tot<<=1;
        lgt++;
    }
    vector<int> FA = FFT(va,tot,lgt),FB = FFT(vb,tot,lgt);
    for(int i = 0;i < tot;i++){
        FA[i] = 1ll*FA[i]*FB[i]%MOD;
    }
    FA = IFFT(FA,tot,lgt);
    FA.resize(n + m + 1);
    int inv = qpow(tot,MOD - 2);
    for(int &v : FA){
        v = 1ll*v*inv%MOD;
    }
    return FA;
}
vector<int> operator+(const vector<int> &va,const vector<int> &vb){
    vector<int> res(va);
    if(vb.size() > va.size()){
        res.resize(vb.size());
    }
    for(int i = 0;i < vb.size();i++){
        res[i] = (res[i] + vb[i])%MOD; 
    }
    return res;
}
int B[N];
int fath[N];
int siz[N];
int son[N];
void dfs1(int x,int fa){
    siz[x] = 1;
    fath[x] = fa;
    for(int v: bian[x]){
        if(v == fa){
            continue;
        }
        dfs1(v,x);
        siz[x] += siz[v];
        if(siz[v] > siz[son[x]]){
            son[x] = v;
        }
    }
}
int S[N];
vector<int> f[2][N];
vector<int> operator%(const vector<int> &v,int m){
    if(v.size() < m){
        return v;
    }
    vector<int> res(v);
    res.resize(m);
    return res;
}
int n,m;
vector<vector<vector<int>>> calc(const vector<int> & ids,int l,int r){
    if(l == r){
        return {{f[0][ids[l]],{0}},{{0},f[1][ids[l]]}};
    }
    int mid = (l + r)/2;
    auto r1 = calc(ids,l,mid);
    auto r2 = calc(ids,mid+1,r);
    return {{   (r1[0][0]*r2[1][0]%m + r1[0][1]*r2[0][0]%m + r1[0][0]*r2[0][0])%m,
                (r1[0][0]*r2[1][1]%m + r1[0][1]*r2[0][1]%m + r1[0][0]*r2[0][1])%m}
            ,{  (r1[1][0]*r2[1][0]%m + r1[1][1]*r2[0][0]%m + r1[1][0]*r2[0][0])%m,
                (r1[1][0]*r2[1][1]%m + r1[1][1]*r2[0][1]%m + r1[1][0]*r2[0][1])%m}};
}
vector<int> mul(const vector<vector<int>> &p1,int l,int r){
    if(l == r){
        return p1[l];
    }
    int tot = 0;
    for(int i = l;i <= r;i++){
        tot += p1[i].size();
    }
    int p = r - 1;
    int tot1 = 0;
    for(int i = l;i<r;i++){
        if(tot1 + p1[i].size() > tot/2){
            p = i;
            break;
        }
    }
    return mul(p1,l,p)*mul(p1,p + 1,r);
}
void dfs2(int x,int tf){
    vector<vector<int>> p1(1,{1}),p2(1,{0,b[x]});
    for(int v : bian[x]){
        if(v == fath[x] || v == son[x]){
            continue;
        }
        dfs2(v,v);
        p1.push_back(f[1][v] + f[0][v]);
        p2.push_back(f[0][v]);
    }
    f[0][x] = mul(p1,0,p1.size() - 1);
    f[1][x] = mul(p2,0,p2.size() - 1);
    if(!son[x]){
        vector<int> ids;
        int cur = x;
        while(x != fath[tf]){
            ids.push_back(x);
            x = fath[x];
        }
        vector<int> v1,v2,v3;
        auto r = calc(ids,0,ids.size() - 1);
        f[0][tf] = r[0][0] + r[1][0];
        f[1][tf] = r[0][1] + r[1][1];
        return;
    }
    dfs2(son[x],tf);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    init();
    cin>>n>>m;
    for(int i = 1;i<=n;i++){
        cin>>b[i];
    }
    for(int i = 1;i < n;i++){
        int u,v;
        cin>>u>>v;
        bian[u].push_back(v);
        bian[v].push_back(u);
    }
    m++;
    dfs1(1,0);
    dfs2(1,1);
    vector<int> res = (f[0][1] + f[1][1])%m;
    cout<<res[m - 1]<<'\n';
}